<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
  <script>
    // es6直接写入变量和函数，作为对象的属性和方法
    const name = '测试',age = 20;
    const person = {
      name,
      age,
      sayName() {
        console.log(this.name);
      }
    }
    person.sayName();

    function fn(x,y){
      return {x,y};
    }
    console.log(fn(1,2));

    let car = {
      wheel:4,
      set(newVal){
        if(newVal < this.wheel){
          throw new Error('轮子数量太少了');
        }
        this.wheel = newVal;
      },
      get(){
        return this.wheel;
      }
    }
    console.log(car.get());
    car.set(5);
    console.log(car.get());

    const obj = {};
    obj.isShow = true;
    const name2 = 'a';
    obj[name2 + 'bc'] = 123;
    obj['f'+'bc'] = function (){
      console.log(this);
    }
    console.log(obj);

    const obj2 = {
      isShow: true,
      [name2 + 'bc']: 123,
      ['f'+name2](){
        console.log(this);
      }
    }
    console.log(obj2);

    // is() 和 ===
    // 比较两个值是否严格相等
    // 结果为false
    console.log(NaN === NaN);
    // 结果为true
    console.log( Object.is(NaN,NaN));

    // assign()
    // 对象的合并
    // Object.assign(target,obj1,obj2....)
    // 返回合并之后的新对象为浅拷贝
    let assign = Object.assign({}, {a: 1, b: 2});
   console.log(assign);
  </script>
</body>
</html>